package com.study.casedemo;

import java.util.Scanner;

public class Demo6 {
    public static void main(String[] args) {
        // 数字加密：规则——对一个多位数的每个位上的数字加5然后再除10取余翻转得到的数就是加密后的数。
        System.out.println("请输入4位数：");
        Scanner sc = new Scanner(System.in);
        int nextInt = sc.nextInt();
        int[] arr = new int[4];
        numToArr(arr,nextInt);
        printArr(arr);
        arrToPas(arr);
        printArr(arr);
        arrTonumber(arr);
    }

    public static void numToArr(int[] arr,int number){
            arr[0] = number/1000;
            arr[1] = (number/100)%10;
            arr[2] = (number/10)%10;
            arr[3] = number%10;
    }

    public static void arrToPas(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (arr[i]+5)%10;
        }
        for (int i = 0,j = arr.length-1; i < j; i++,j--) {
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
    }

    public static void printArr(int[] arr){
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(i == arr.length-1? arr[i] : arr[i]+", ");
        }
        System.out.println("]");
    }

    public static void arrTonumber(int[] arr){
        int number = arr[0]*1000 + arr[1]*100+arr[2]*10+arr[3];
        System.out.println(number);
    }
}
